package hk.ust.comp3111.ustnutrition.formula;

import hk.ust.comp3111.ustnutrition.data.db.User;

public class NutritionCalculator
{
	public NutritionCalculator(User user)
	{
		mUser = user;
	}

	public void calc()
	{
		double ibw = Math.pow(mUser.getHeight(), 2) * 22.0 / 10000.0;
		double ratio = mUser.getWeight() / ibw;

		double x = 0;

		if (ratio <= 0.9)
			x = ibw * 35;
		else if (ratio >= 1.1)
			x = ibw * 25;
		else
			x = ibw * 30;

		double y = 0;
		if (18 <= mUser.getAge() && mUser.getAge() <= 29)
		{
			y = x + 300;
			if (mUser.isFemale())
			{
				y -= 200;
			}
		}
		else if (30 <= mUser.getAge() && mUser.getAge() <= 59)
		{
			y = x + 250;
			if (mUser.isFemale())
			{
				y -= 200;
			}
		}
		else
		{
			y = x;
			if (mUser.isFemale())
			{
				y -= 100;
			}
		}

		double energyNeed = 0;
		switch (mUser.getExercise())
		{
		case ALWAYS:
			energyNeed = y + 600;
			break;

		default:
		case SOMETIMES:
			energyNeed = y + 300;
			break;

		case SELDOM:
			energyNeed = y;
			break;
		}

		carbohydratesNeed = energyNeed * 0.65 / 4.0;
		proteinNeed = energyNeed * 0.15 / 4.0;
		fatNeed = energyNeed * 0.2 / 9.0;
		sodiumNeed = 2.0;
	}

	public double getCarbohydratesNeed()
	{
		return carbohydratesNeed ;
	}

	public double getProteinNeed()
	{
		return proteinNeed;
	}

	public double getFatNeed()
	{
		return fatNeed;
	}

	public double getSodiumNeed()
	{
		return sodiumNeed;
	}

	private User mUser;
	private double carbohydratesNeed, proteinNeed, fatNeed, sodiumNeed; // nutrition need
}
